#include "slepdef.h"
#include <stdlib.h>


slep_vector* slepAllocVector(int memory, slep_sparsity sparsity){
	if(sparsity == SlepDense)
		return slepAllocDenseVector(memory);
	else
		return slepAllocSparseVector(memory);
}

slep_vector* slepAllocDenseVector(int size){
	slep_vector* vctr1 = (slep_vector*)malloc( sizeof(slep_vector) );
	vctr1->data.vctr = (double *) malloc( size * sizeof(double));
	vctr1->dim = size;
	vctr1->sparsity = SlepDense;
	return vctr1;
}
slep_vector* slepAllocSparseVector(int nnz){
	slep_vector* vctr1 = (slep_vector*)malloc( sizeof(slep_vector) );
	vctr1->data.spvctr.values = (double *) malloc( sizeof(double) * nnz);
	vctr1->data.spvctr.index = (int *) malloc( sizeof(int) * nnz);
	vctr1->data.spvctr.nnz = nnz;
	vctr1->sparsity = SlepSparse;
	vctr1->dim = nnz+1;
	return vctr1;
}

slep_matrix* slepAllocDenseMatrix(int m,int n){
	slep_matrix* mtrx1 = (slep_matrix*) malloc( sizeof(slep_matrix) );
	mtrx1->m = m;
	mtrx1->n = n;
	mtrx1->sparsity = SlepDense;
	mtrx1->uplobanded = SlepFull;
	mtrx1->data.mtrx = 0;
	mtrx1->data.mtrx = (double *) malloc(sizeof(double) * m * n);
	return mtrx1;
}
slep_matrix* slepAllocSparseMatrix(int m,int nnz){
	slep_matrix* mtrx1 = (slep_matrix*) malloc( sizeof(slep_matrix) );
	mtrx1->m = m;
	mtrx1->sparsity = SlepSparse;
	mtrx1->data.spmtrx.format = SlepCompressedSparseColumn;
	mtrx1->data.spmtrx.ColumnsORRows = (int *) malloc( sizeof(int) * (m+1) );
	mtrx1->data.spmtrx.Index = (int *) malloc( sizeof(int) * nnz );
	mtrx1->data.spmtrx.values = (double *) malloc( sizeof(double) * nnz );
	return mtrx1;
}

